package com.tianruan.dc.modules.sys.user.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tianruan.dc.modules.sys.user.entity.dto.WordLearnDTO;
import com.tianruan.dc.modules.sys.user.mapper.WordLearnMapper;
import com.tianruan.dc.modules.sys.user.service.IWordLearmService;
import com.tianruan.dc.modules.sys.user.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: AmiroKD
 * @CreateTime: 2024-07-09
 * @Version: 1.0
 */

@Service
public class WordLearnServiceImpl implements IWordLearmService {

    @Autowired
    WordLearnMapper wordLearnMapper;

    /**
     * 分页查询单词
     * @param page
     * @param pageSize
     * @param word
     * @return
     */
    @Override
    public PageBean page(Integer page, Integer pageSize, String word) {
        PageHelper.startPage(page,pageSize);
        List<WordLearnDTO> wordLearnList = wordLearnMapper.list(word);
        Page<WordLearnDTO> p = (Page<WordLearnDTO>) wordLearnList;
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }

    /**
     * 修改背诵状态
     * @param wordLearnDTO
     */
    @Override
    public void updateFlag(WordLearnDTO wordLearnDTO) {
        wordLearnMapper.updateFlag(wordLearnDTO.getWord(),wordLearnDTO.getFlag());
    }

    /**
     * 判断单词是否存在
     * @param word
     * @return
     */
    @Override
    public boolean isWordExist(String word) {
        return wordLearnMapper.getWord(word) == null;
    }
}
